'use strict';

const Service = require('egg').Service;

class ScoreService extends Service {
    //添加
    async add(username,theory,skill,timer) {
        await this.app.mysql.query('insert into scorelist (username,theory,skill,timer) values (?,?,?,?)',[username,theory,skill,timer])
    }

    //删除
    async destroy(id){
        await this.app.mysql.query('delete from scorelist where id=?',[id])
    }

    //查询
    async index(curTime){
        return await this.app.mysql.query('select * from scorelist where timer=?',[curTime])
    }

    //修改
    async update(theory,skill,id){
        await this.app.mysql.query('update scorelist set theory=?,skill=? where id=?',[theory,skill,id])
    }

    //获取未录入成绩的人员名单
    async notScore(curTime){
        return await this.app.mysql.query('select username from userlist where role_id != 1 and username not in (select username from scorelist where timer=?)',[curTime])
    }

    //搜索
    async search(key,curTime){
        return await this.app.mysql.query(`select * from scorelist where username like '%${key}%' and timer=?`,[curTime])
    }
}

module.exports = ScoreService;
